package com.xidian.zhiancloud.service.luling.RiskIdentificationPart;

import com.xidian.zhiancloud.dao.RiskIdentStatusMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.RiskIdentStatus;
import com.xidian.zhiancloud.model.RiskIdentStatusExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RiskIdentStatusService {
    @Autowired
    private RiskIdentStatusMapper riskIdentStatusMapper;

    public void insertByIds(Long[] ids) {
        for (Long id : ids) {
            int result = riskIdentStatusMapper.deleteByPrimaryKey(id);
            if (result == 0) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
        }

    }

    public List<RiskIdentStatus> getById(String state) {
        RiskIdentStatusExample riskIdentStatusExample = new RiskIdentStatusExample();
        RiskIdentStatusExample.Criteria criteria = riskIdentStatusExample.createCriteria();
        criteria.andStateEqualTo(state);
        List<RiskIdentStatus> riskIdentStatusList = riskIdentStatusMapper.selectByExample(riskIdentStatusExample);
        if (riskIdentStatusList == null) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
        return riskIdentStatusList;
    }


  /* public List<RiskIdentStatus>getById(String type) {
        RiskIdentStatusExample riskIdentStatusExample = new RiskIdentStatusExample();
        RiskIdentStatusExample.Criteria criteria = riskIdentStatusExample.createCriteria();
        criteria.andStateEqualTo(type);
        List<RiskIdentStatus>riskIdentStatusList = riskIdentStatusMapper.selectByExample(riskIdentStatusExample);
        if (riskIdentStatusList == null) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
        return riskIdentStatusList;
    }*/

    public Object getList(String riskName, Date deadlineIden, String type, String key, int current, int size) {

        RiskIdentStatusExample riskIdentStatusExample = new RiskIdentStatusExample();
        RiskIdentStatusExample.Criteria criteria1 = riskIdentStatusExample.createCriteria();
        RiskIdentStatusExample.Criteria criteria2 = riskIdentStatusExample.createCriteria();
        RiskIdentStatusExample.Criteria criteria3 = riskIdentStatusExample.createCriteria();
        if(riskName != null){
            criteria1.andRiskNameEqualTo(riskName);
            criteria2.andRiskNameEqualTo(riskName);
            criteria3.andRiskNameEqualTo(riskName);
        }

        if (type != null) {
            criteria1.andTypeEqualTo(type);
            criteria2.andTypeEqualTo(type);
            criteria3.andTypeEqualTo(type);
        }
        if (deadlineIden != null) {
            criteria1.andDeadlineIdenEqualTo(deadlineIden);
            criteria2.andDeadlineIdenEqualTo(deadlineIden);
            criteria3.andDeadlineIdenEqualTo(deadlineIden);
        }
        if (key != null && !"".equals(key)) {
//            criteria1.andDeadlineIdenEqualTo('%' + key + '%');
            criteria2.andTypeEqualTo('%' + key + '%');
            criteria3.andRiskNameEqualTo('%' + key + '%');
            riskIdentStatusExample.or(criteria2);
            riskIdentStatusExample.or(criteria3);
        }
        Integer a = 3;
        Integer b = 6;
        criteria1.andStateEqualTo(a.toString());
        criteria2.andStateEqualTo(b.toString());
        riskIdentStatusExample.or(criteria2);
        return riskIdentStatusMapper.selectByExampleWithRowbounds(riskIdentStatusExample, new RowBounds(current, size));
    }


}



